﻿using NMoq.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Reflection;

namespace NMoq.Core.UnitTest
{
    
    
    /// <summary>
    ///This is a test class for DelegateExtensionTest and is intended
    ///to contain all DelegateExtensionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class DelegateExtensionTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for IsEquivalent
        ///</summary>
        [TestMethod()]
        public void IsEquivalentTest()
        {
            Delegate implDelegate;
        

            Type customerType=typeof (Customer);
            MethodInfo getNameMethod = customerType.GetMethod("GetName");
            implDelegate = new Func<string>(() => { return "dfdas"; });
            Assert.IsTrue(implDelegate.IsEquivalent(getNameMethod));

            MethodInfo getCustomerMethod = customerType.GetMethod("GetCustomer");
            implDelegate = new FuncRef<string ,int ,string,Customer>((ref string name,out int id, string desc)=>{
                id = 9;
                return new Customer ();
            });
            Assert.IsTrue (implDelegate.IsEquivalent (getCustomerMethod));
        }
    }

    internal delegate TResult FuncRef<T1,T2,T3,TResult>(ref T1 arg1,out T2 arg2, T3 arg3);
    internal sealed class Customer
    {
        
        internal class Product { }

        public string GetName() { return string.Empty; }
        public Customer GetCustomer(ref string name,out int id,string desc) {
            id = 10;
            return new Customer (); 
        }
        public Product GetProduct(string name)
        {
            return new Product();
        }
    }
}
